<template>
	<view>
		<view class="Large-box">
			<view class="business-Dishes">
				<text>你对商家/菜品满意吗？</text>
			</view>
			<view class="business">
				<text>{{businessData.name}}</text>
			</view>
			<view class="Score total-s">
				<view class="total-score">
					<text>总体</text>
					<u-rate :count="count" :value="averageValue" @change="change" size="50rpx"></u-rate>
				</view>
				<text v-if="averageValue">{{evaluate(averageValue)}}</text>
			</view>
			<view class="Score">
				<view class="taste-score">
					<text>口味</text>
					<u-rate :count="count" v-model="evalutionForm.testValue" gutter="1"></u-rate>
				</view>
				<text v-if="averageValue">{{evaluate(evalutionForm.testValue)}}</text>
			</view>
			<view class="Score">
				<view class="taste-score">
					<text>环境</text>
					<u-rate :count="count" v-model="evalutionForm.atmosValue" gutter="1"></u-rate>
				</view>
				<text v-if="averageValue">{{evaluate(evalutionForm.atmosValue)}}</text>
			</view>
			<view class="reviewContent">
				<u--textarea v-model="evalutionForm.contentValue" placeholder="请输入内容" height="400rpx"></u--textarea>
				<view class="imageUpload" @click="toUpload">
					<image class="add-icon1" :src="evalutionForm.image ? evalutionForm.image : '../../../static/me/add_icon1.png'"></image>
					<!-- <u-icon name="camera" size="60rpx"></u-icon> -->
					<text>添加图片</text>
				</view>
			</view>
		</view>
		<view class="submit" @click="submit()">
			<u-button text="提交" color="#f29100"></u-button>
		</view>
	</view>
</template>

<script>
	import { BusinessDetail, publishEvaluation } from '@/common/http.api.js'
	import { uploadUrl } from '@/common/http.interceptor.js'
	export default {
		data() {
			return {
				uploadUrl,
				evalutionForm:{
					contentValue: '',
					testValue: '',
					atmosValue: '',
					image:''
				},
				count: 5,
				oldkouwei: 0,
				huanjing: 2,
				oldhuanjing: 0,
				total:0,
				orderId:'',
				businessData: {}
			}
		},
		onLoad(id) {
			this.orderId = id.orderId
			this.oldhuanjing = this.huanjing
			this.oldkouwei = this.evalutionForm.testValue
			// this.total=(this.huanjing+this.kouwei)/2
			
			BusinessDetail().then( res => {
				this.businessData = res.rows[0]
			})
		},
		methods: {
			change(value) {
				this.total=value
				if (this.evalutionForm.testValue === this.oldkouwei && this.evalutionForm.atmosValue === this.oldhuanjing) {
					this.evalutionForm.testValue = value
					this.oldkouwei = value
					this.evalutionForm.atmosValue = value
					this.oldhuanjing = value
				} else if (this.evalutionForm.testValue === this.oldkouwei) {
					this.oldhuanjing = this.evalutionForm.atmosValue
				} else if (this.evalutionForm.atmosValue === this.oldhuanjing) {
					this.oldkouwei = this.evalutionForm.testValue
				}
			},
			evaluate(value) {
				if (value<=1.5) {
					return '极差';
				} else if (value>1.5&&value<=2.5) {
					return '差';
				} else if (value>2.5&&value<=3.5) {
					return '一般';
				}else if (value>3.5&&value<=4.5) {
					return '满意';
				}else if (value>4.5&&value<=5) {
					return '非常满意';
				}
			},
			submit(){
				const evaForm = {
					userId: this.userId,
					orderId: this.orderId,
					content: this.evalutionForm.contentValue,
					grade: this.averageValue,
					image: this.evalutionForm.image
				}
				console.log(evaForm)
				publishEvaluation(evaForm).then( res => {
					uni.showToast({
					    icon: 'success',
					    text: '修改成功'
					})
					// 去完成订单页面
					uni.navigateTo({
						url: `/pagesB/order/completeEvaluation/completeEvaluation`
					})
				})
			},
			
			//上传图片
			toUpload() {
				uni.chooseImage({
					success: (chooseImageRes) => {
						const tempFilePaths = chooseImageRes.tempFilePaths;
						uni.uploadFile({
							url: this.uploadUrl,
							header: {
								token: this.$store.state.token
							},
							filePath: tempFilePaths[0],
							name: 'file',
							success: (uploadFileRes) => {
								this.evalutionForm.image = JSON.parse(uploadFileRes.data).msg
								console.log(this.evalutionForm.image, 123)
							}
						});
					}
				})
			},

		},
		
		computed:{
			averageValue(){
				const average = (this.evalutionForm.testValue + this.evalutionForm.atmosValue)/2
				return average
			}
		}
	
	}
</script>

<style>
	page {
		background-color: #eee;
	}

	.Large-box {
		background-color: #fff;
		margin: 20rpx;
		border-radius: 30rpx;
		border: 1rpx solid #fff;
	}

	.Large-box .business-Dishes {
		font-size: 38rpx;
		font-weight: bold;
		margin: 20rpx;
		height: 70rpx;
		border-bottom: solid #eee thin;
	}

	.Large-box .business {
		height: 100rpx;
		margin-left: 20rpx;
		display: flex;
	}

	.Large-box .business image {
		height: 90rpx;
		width: 90rpx;
		border-radius: 20rpx;
	}

	.Large-box .business text {
		line-height: 90rpx;
		margin-left: 20rpx;
	}

	.Large-box .Score {
		margin: 20rpx;
		display: flex;
	}

	.Large-box .Score .total-score {
		display: flex;
		margin-right: 80rpx;
	}

	.Large-box .Score .total-score text {
		margin-right: 10rpx;
	}

	.Large-box .Score .taste-score {
		display: flex;
		margin-right: 70rpx;
	}

	.Large-box .Score .taste-score text {
		margin-right: 30rpx;
	}

	.Large-box .total-s {
		font-size: 38rpx;
	}

	.Large-box .reviewContent {
		/* height: 500rpx; */
		background-color: #eee;
		margin: 20rpx;
		border-radius: 10rpx;
		position: relative;
	}

	.Large-box .reviewContent .imageUpload {
		height: 120rpx;
		width: 140rpx;
		border: 1rpx solid #c8c9cc;
		position: absolute;
		bottom: 20rpx;
		left: 20rpx;
		text-align: center;
		border-radius: 10rpx;
		z-index: 10;
	}
	.Large-box .reviewContent .imageUpload .add-icon1 {
		width: 120rpx;
		height: 120rpx;
	}
	.Large-box .reviewContent .imageUpload .u-icon {
		margin-top: 10rpx;
		margin-left: 40rpx;
	}

	.Large-box .reviewContent .imageUpload text {
		font-size: 25rpx;
		color: #82848a;
	}

	.submit {
		height: 70rpx;
		width: 200rpx;
		margin: auto;
		margin-top: 50rpx;
	}

	.submit u-button {}
</style>
